﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Security;
using System.Runtime.InteropServices;

namespace SimpleInfrastructure.Exceptions
{
    public static class ExceptionExtensions
    {
        public static bool IsFatal(this Exception ex)
        {
            return ex is FatalException ||
                ex is StackOverflowException ||
                ex is OutOfMemoryException ||
                ex is AccessViolationException ||
                ex is AppDomainUnloadedException ||
                ex is ThreadAbortException ||
                ex is SecurityException ||
                ex is SEHException;
        }

        public static Exception GetInnestException(this Exception ex)
        {
            var innerException = ex.InnerException;
            var exception2 = ex;
            while (innerException != null)
            {
                exception2 = innerException;
                innerException = innerException.InnerException;
            }
            return exception2;
        }
    }
}
